package com.feng.picture.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * 构造本地缓存
 */
@Configuration
public class CaffeineConfig {

    @Bean
    public Cache<String, String> cacheManager() {
        final Cache<String, String> LOCAL_CACHE = Caffeine.newBuilder()
                .initialCapacity(1024)
                .maximumSize(10_000L)
                // 缓存5分钟失效
                .expireAfterWrite(Duration.ofMinutes(5))
                .build();

        return LOCAL_CACHE;
    }
}
